//
//  UITableView+BIDHaveEmptyData.m
//  HJGJCommunity
//
//  Created by mal on 2017/6/24.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "UITableView+BIDHaveEmptyData.h"

@implementation UITableView (BIDHaveEmptyData)

- (void)showEmptyView
{
    UIView *subView = [self viewWithTag:999];
    if(subView)
    {
        return;
    }
    CGRect ownFrame = self.frame;
    CGFloat labelHeight= 20.f;
    CGFloat emptyViewWidth = ownFrame.size.width/2;
    CGFloat emptyViewHeight = emptyViewWidth+labelHeight;
    CGFloat posX = (ownFrame.size.width-emptyViewWidth)/2;
    CGFloat posY = (ownFrame.size.height-emptyViewHeight)/2-64;
    UIView *emptyView = [[UIView alloc] initWithFrame:CGRectMake(posX, posY, emptyViewWidth, emptyViewHeight)];
    emptyView.tag = 999;
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, emptyViewWidth, emptyViewHeight-labelHeight)];
    [imgView setImage:[UIImage imageNamed:@"emptyData.png"]];
    [emptyView addSubview:imgView];
    //
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(imgView.frame), emptyViewWidth, labelHeight)];
    [label setTextAlignment:NSTextAlignmentCenter];
    [label setText:@"暂无任何信息"];
    [label setTextColor:RGBACOLOR(54, 158, 149, 1)];
    [label setFont:[UIFont systemFontOfSize:15.f]];
    [emptyView addSubview:label];
    //
    [self addSubview:emptyView];
}

- (void)hideEmptyView
{
    UIView *subView = [self viewWithTag:999];
    if(subView)
    {
        [subView removeFromSuperview];
    }
}

@end
